package com.ontheroad.controller;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ontheroad.api.response.Response;
import com.ontheroad.user.model.UserDto;
import com.ontheroad.user.service.UserTopicService;
import com.ontheroad.utils.JsonUtils;

/**
 * 
 */
@RestController
@RequestMapping("topic/")
public class UserTopicController extends BaseController {

	@Autowired
	private UserTopicService userTopicService;

	@RequestMapping(value = "regist", method = RequestMethod.POST)
	public HashMap<String, Object> regist(String requestData) {
		try {
			UserDto user = (UserDto) JsonUtils.jsonToObject(requestData,
					UserDto.class);
			return userTopicService.regist(user);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@RequestMapping(value = "login", method = RequestMethod.POST)
	public HashMap<String, Object>  login(String requestData) {
		try {
			UserDto user = (UserDto) JsonUtils.jsonToObject(requestData,
					UserDto.class);
			return userTopicService.login(user);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@RequestMapping(value = "Thirdlogin", method = RequestMethod.POST)
	public Response Thirdlogin(String requestData) {
		try {
			UserDto user = (UserDto) JsonUtils.jsonToObject(requestData,
					UserDto.class);
			return userTopicService.ThirdLogin(user);
		} catch (Exception e) {
			e.printStackTrace();
			return Response.ERROR("服务异常");
		}
	}

}
